package com.lzc.lblog.lblog.templates;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lzc.lblog.lblog.common.templates.DirectiveHandler;
import com.lzc.lblog.lblog.common.templates.TemplateDirective;
import com.lzc.lblog.lblog.service.MPostService;
import com.lzc.lblog.lblog.vo.PostVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 自定义获取置顶博客标签
 */
@Component
public class CustomTagDirective extends TemplateDirective {

    @Autowired
    private MPostService mPostService;

    @Override
    public String getName() {
        return "posts";
    }

    @Override
    public void execute(DirectiveHandler handler) throws Exception {
        Integer level = handler.getInteger("level");
        Integer pn = handler.getInteger("pn", 1);
        Integer size = handler.getInteger("size", 2);
        Long categoryId = handler.getLong("categoryId");
        Integer status = handler.getInteger("status");
        Boolean recommend = handler.getBoolean("recommend");
        String order = handler.getString("order");
        IPage<PostVo> postVoIPage = mPostService.paging(new Page(pn, size), categoryId, level, recommend, null, order,status);
        handler.put(RESULTS,postVoIPage).render();
    }
}
